﻿using System;
using System.Collections.Generic;

namespace Nextensions.Net.HTML
{
    public class Document: Element
    {
        private readonly Dictionary<string, Form> _forms = new Dictionary<string, Form>();
        private readonly Dictionary<string, Input> _inputElements = new Dictionary<string, Input>();
        private readonly Dictionary<string, Element> _elements = new Dictionary<string, Element>();
        private readonly string _html = String.Empty;

        public Document(string HTML):base(HTML)
        {
            ElementFactory<Form>.CreateChildElements(this, Tags.Form);
            ElementFactory<Input>.CreateChildElements(this, Tags.Input, Tags.Select);
        }

        public override void AddElement(Element Element)
        {
            if (Element is Form)
            {
                string name = Element.Name == null ?
                    String.Format("form{0}", Forms.Count + 1) :
                    Element.Name;

                _forms.Add(name, (Form)Element);
            }
            else if (Element is Input)
            {
                _inputElements.Add(Element.Name, (Input)Element);
            }
            else
            {

                _elements.Add(Element.Name, Element);
            }
        }

        public Dictionary<string, Input> InputElements
        {
            get
            {
                return _inputElements;
            }
        }

        public Dictionary<string, Element> Elements
        {
            get
            {
                return _elements;
            }
        }

        public Dictionary<string, Form> Forms
        {
            get
            {
                return _forms;
            }
        }
    }
}
